package com.gs.gulishopp.gulishoppcoupon;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;


@EnableDiscoveryClient
@MapperScan("com.gs.gulishopp.gulishoppcoupon.dao")
@SpringBootApplication

public class GulishoppCouponApplication {
    static Logger logger = LoggerFactory.getLogger(GulishoppCouponApplication.class);

    public static void main(String[] args) throws InterruptedException {
        /* SpringApplication.run(GulishoppCouponApplication.class, args);*/
        ConfigurableApplicationContext applicationContext = SpringApplication.run(GulishoppCouponApplication.class, args);
        while (true) {
            //当动态配置刷新时，会更新到 Enviroment中，因此这里每隔一秒中从Enviroment中获取配置
            String userName = applicationContext.getEnvironment().getProperty("coupon.user.name");
            String userAge = applicationContext.getEnvironment().getProperty("coupon.user.age");
            logger.info("配置信息，名称：{}，年龄：{}", userName, userAge);
            TimeUnit.SECONDS.sleep(1);

        }
    }

}
